package design.pattern.application.CommandAndChain;

/**
 * @program JavaBase
 * @description:
 * @author: zhanglu
 * @create: 2020-05-22 14:31:00
 */
public abstract class CommandName {

    private CommandName nextOperator;
    public final String handleMessage(CommandVo vo){
        //处理结果
        String result = null;
        //实现
        if(vo.getParam().size() == 0 || vo.getParam().contains(this.getOperatorParam())){
            result = this.echo(vo);
        }else {
            if(this.nextOperator != null){
                result = this.nextOperator.handleMessage(vo);
            }else {
                result = "命令无法执行";
            }
        }
        return result;
    }
    //设置剩余参数由谁来处理
    public void setNext(CommandName nextOperator){
        this.nextOperator = nextOperator;
    }
    //每个处理者都要处理一个后缀参数
    protected abstract String getOperatorParam();
    //每个处理者都必须实现处理任务
    protected abstract String echo(CommandVo vo);

}
